/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HapusGajiGUI.java
 *
 * Created on 26 Jul 12, 9:26:49
 */
package gui;

import dao.GajiDAO;
import javax.persistence.EntityManager;
import javax.swing.JOptionPane;

/**
 *
 * @author Bramso
 */
public class HapusGajiGUI extends javax.swing.JInternalFrame {

    EntityManager em;
    /** Creates new form HapusGajiGUI */
    public HapusGajiGUI(EntityManager em) {
        initComponents();
        this.em = em;
        this.bindingKode();
    }

    public void bindingKode(){
         GajiDAO dao = new GajiDAO(em);
        kode_cmb.removeAllItems();
        for (int i = 0; i < dao.getAll().size(); i++) {
             kode_cmb.addItem(dao.getAll().get(i).getKode());
            
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        kode_cmb = new javax.swing.JComboBox();
        hapus_btn = new javax.swing.JButton();
        keluar_btn = new javax.swing.JButton();

        setTitle("Hapus Gaji");

        jLabel1.setText("Kode Gaji");

        hapus_btn.setText("Hapus");
        hapus_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hapus_btnActionPerformed(evt);
            }
        });

        keluar_btn.setText("Keluar");
        keluar_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                keluar_btnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(hapus_btn)
                        .addGap(18, 18, 18)
                        .addComponent(keluar_btn))
                    .addComponent(kode_cmb, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(kode_cmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hapus_btn)
                    .addComponent(keluar_btn))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void keluar_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keluar_btnActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_keluar_btnActionPerformed

    private void hapus_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hapus_btnActionPerformed
        // TODO add your handling code here:
        GajiDAO dao = new GajiDAO(em);
        try {
            
            JOptionPane.showMessageDialog(this, dao.Delete(kode_cmb.getSelectedItem().toString()));
            
            this.bindingKode();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_hapus_btnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton hapus_btn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton keluar_btn;
    private javax.swing.JComboBox kode_cmb;
    // End of variables declaration//GEN-END:variables
}
